﻿using System;
using System.Windows;
using Microsoft.Practices.Unity;
using SportTraining.Core.Dal;
using SportTraining.Helpers;

namespace SportTraining
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static IUnityContainer Container { get; set; }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            Logger.Log.Info("Старт...");

            try
            {
                Container = ContainerHelper.CreateContainer();

                #region создание БД если необходимо
                // БД создаётся в конструкторе DataContext  ???
                Container.Resolve<IDataContext>();
                #endregion
            }
            catch (Exception err)
            {
                Logger.Log.Fatal("ApplicationStartup", err);

                MessageBox.Show(err.Message, "Ошибка инициализации программы", MessageBoxButton.OK,
                                MessageBoxImage.Stop);

                Current.Shutdown();
            }
        }

        private void Application_Exit(object sender, ExitEventArgs e)
        {
            Logger.Log.Info("Стоп...");
        }
    }
}